import * as Types from './types'
import {PaginatedData} from "@/api/common";
import request from "@/utils/request";
import {ArticleTagCountResp} from "./types";

//查询文章
export async function pageArticle(req: Types.ArticlePageReq): Promise<PaginatedData<Types.ArticlePageResp>> {
    return request.post('/article/page', req)
}
export async function queryRecentArticle(req: Types.ArticleRecentReq ): Promise<Types.ArticleRecentResp[]> {
    return request.post('/article/recent', req)
}

export async function countArticleCategory(req: Types.ArticleCategoryCountReq): Promise<Types.ArticleCategoryCountResp[]> {
    return request.post('/article/category/count', req)
}

export async function getArticleDetail(id: number): Promise<Types.ArticleDetailResp> {
    return request.get('/article/detail?id=' + id)
}

export async function starArticle(req: Types.ArticleStarReq): Promise<Types.ArticleDetailResp> {
    return request.post('/article/star', req)
}

export async function pageArticleComment(req: Types.ArticleCommentPageReq): Promise<PaginatedData<Types.ArticleCommentPageResp>> {
    return request.post('/article/comment/page', req)
}

export async function publishArticleComment(req: Types.ArticleCommentPublishReq): Promise<void> {
    return request.post('/article/comment/publish', req)
}

export async function publishNewArticle(req: Types.ArticlePublishReq): Promise<number> {
    return request.post('/article/publish', req)
}

export async function saveArticleDraft(req: Types.ArticleSaveDraftReq): Promise<number> {
    return request.post('/article/saveDraft', req)
}

export async function getArticleCategoryTree(): Promise<Types.Category[]> {
    return request.get('/article/category/tree')
}
//发布评论回复
export async function publishArticleCommentReply(req: Types.ArticleCommentReplyPublishReq): Promise<number> {
    return request.post('/article/comment/reply/publish', req)
}
export async function countArticleTag(): Promise<Types.ArticleTagCountResp[]> {
    return request.get('/article/tag/count')
}